<template>
  <div class="login-container">
    <!-- 左边 -->
    <div class="logo" />
    <!-- 右边 -->
    <div class="form">
      <h1>智慧园区-登录</h1>

      <el-card shadow="never" class="login-card">
        <!--登录表单-->
        <el-form ref="loginRef" :model="loginForm" :rules="loginRules">
          <el-form-item prop="username">
            <p>账号</p>
            <el-input v-model="loginForm.username" placeholder="请输入账号" />
          </el-form-item>

          <el-form-item prop="password">
            <p>密码</p>
            <el-input v-model="loginForm.password" show-password placeholder="请输入密码" />
          </el-form-item>

          <el-form-item prop="uuid">
            <p>模型uuid:</p>
            <el-input v-model="loginForm.uuid" show-password placeholder="请输入uuid:" />
          </el-form-item>

          <el-form-item prop="isAgree">
            <el-checkbox v-model="loginForm.isAgree">记住我</el-checkbox>
          </el-form-item>

          <el-form-item>
            <el-button style="width:350px" type="primary" @click="login">登录</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </div>
</template>

<script>

export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        username: process.env.NODE_ENV === 'development' ? 'demo' : '',
        password: process.env.NODE_ENV === 'development' ? 'Hmzs%001' : '',
        uuid: process.env.NODE_ENV === 'development' ? '66ea8d2a-7416-4be5-ba7e-c030cf88b3f3' : '',
        isAgree: process.env.NODE_ENV === 'development'
      },
      loginRules: {
        username: [
          { required: true, message: '请输入账号', trigger: 'blur' },
          { min: 4, max: 16, message: '账号格式不正确', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 16, message: '密码长度应该为6-16位之间', trigger: 'blur' }
        ],
        isAgree: [
          { validator: (rule, value, callback) => { value ? callback() : callback('请阅读用户协议并同意') } }
        ],
        uuid: [{ required: true, message: '请输入uuid', trigger: 'blur' },
          { pattern: /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/, message: '请输入任意生成的模型id!', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    async login() {
      await this.$refs.loginRef.validate()
      const { username, password } = this.loginForm
      this.$store.dispatch('user/login', { username, password })
    }
  }
}
</script>

<style lang="scss" >
.login-container{
  padding-bottom: 76px;
  display: flex;
  align-items: stretch;
  height: 100vh;
  .logo {
    flex: 4;
    background: rgba(38, 72, 176) url(../../assets/common/login-bg-e4ea539c.svg) no-repeat center / cover;
    border-top-right-radius: 60px;
  }

  .form {
    flex: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-left: 176px;

    h1{
    font-size: 26px;
    font-weight: 500;
    color: #1e2023;
    padding-left: 19px;
}

    p {
    color: #8b929d;
      font-size: 16px;
      width: 300px;
      margin-top: 20px;
      margin-bottom: 4px;
    }

    .el-card {
      border: none;
      padding: 0;
    }

   ::v-deep .el-input {
      width: 350px;
      height: 44px;
      .el-input__inner {
        background: #f4f5fb;
      }
    }

    ::v-deep .el-checkbox {
      color: #606266;
    }
  }
}
</style>
